package com.ls.hnks.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.alibaba.fastjson.JSON;
import com.ls.hnks.util.Result;
import com.ls.hnks.util.ResultCodeEnum;
import com.ls.hnks.model.Customer;
import com.ls.hnks.service.CustomerService;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@SaCheckLogin
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/list")
    public Result list(@ApiParam("分页查询的页码数") @RequestParam(value = "page",defaultValue = "1")Integer page,
                       @ApiParam("分页查询的页大小") @RequestParam(value = "size",defaultValue = "20")Integer size){
        return customerService.getCustomerByPage(page,size);
    }

    @RequestMapping("/details/{id}")
    public Result getDetails(@PathVariable String id){
        return customerService.getDetails(id);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Customer customer){
        log.info("顾客信息 --- {}", JSON.toJSONString(customer));
        customerService.saveCustomer(customer);
        return Result.ok();
    }

    @SaCheckRole("admin")
    @PostMapping("/remove/{id}")
    public Result remove( @PathVariable String id){
        return customerService.removeCustomer(id);
    }
}
